#include "lovelight.h"

int uncompress(char* *ptr)
{
   /* 3,456,300 */
   
    char buf[250];
    char cmd[250];
    int filesize;
    char *str;
    FILE* fp;
    int count;

    int i,j;
    
    GetCurrentDirectory(250,buf);
    wsprintf(cmd,"%s\\ll.bin",buf);
    
    if((fp=fopen(cmd,"rb"))==NULL){
        MessageBoxA(NULL,"Fatal Error!","Missing ll.bin!",MB_OK);
        exit(1);
    }
    
    fseek(fp,0,SEEK_END);
    filesize=ftell(fp);
    /*
    printf("\nfilesize=%d\n",filesize);
    getch();
    */
    fseek(fp,0,SEEK_SET);
    str=(char*)malloc(filesize*8);
    
    if(str==NULL){
        MessageBoxA(NULL,"Fatal Error!","No enough memory!",MB_OK);
        exit(1);
    }
    
    count=0;

    
    while(!feof(fp)){
        
        fread(buf,1,250,fp);
        
            
        for(i=0;i<250;++i){
            for(j=0;j<8;++j){
                if((1<<j)&buf[i]){
                    *(str+count*80*25+i*8+j)='*';
                }else{
                    *(str+count*80*25+i*8+j)=' ';
                }    
            }
        }  
        *(str+(count+1)*80*25-2)='\0';
        ++count;
    }
    
    fclose(fp);
    
    *ptr=str;

    return count;
}
        
        
